Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync::watch::Receiver: Fix changed handling on version overflow #6017

Merged

Conversation

uklotzde
Copy link
Contributor

Motivation

sync::watch::Receiver: The asymmetric implementation of Version::decrement() fails after an overflow of the version number. This is an edge case that might occur in long running applications.

Solution

Consistently use wrapping add/sub semantics for both AtomicUsize and usize operations when incrementing/decrementing version numbers. This also allows to start the version numbering at 0 as before.

@github-actions github-actions bot added the R-loom-sync Run loom sync tests on this PR label Sep 19, 2023
@uklotzde uklotzde changed the title sync::watch: Fix changed handling on version overflow sync::watch::Receiver: Fix changed handling on version overflow Sep 19, 2023
@uklotzde uklotzde force-pushed the sync-watch-fix-changed-handling-on-overflow branch from 10bd2f4 to 5efb901 Compare September 19, 2023 15:18
@uklotzde
Copy link
Contributor Author

I have also added and renamed some constants. They depend on each other and their definition and documentation should be colocated.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Sep 19, 2023
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Darksonn Darksonn changed the title sync::watch::Receiver: Fix changed handling on version overflow sync::watch::Receiver: Fix changed handling on version overflow Sep 19, 2023
@Darksonn Darksonn enabled auto-merge (squash) September 19, 2023 15:30
@Darksonn Darksonn merged commit ad7f988 into tokio-rs:master Sep 19, 2023
72 of 73 checks passed
@uklotzde uklotzde deleted the sync-watch-fix-changed-handling-on-overflow branch September 19, 2023 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync R-loom-sync Run loom sync tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants